<?php

namespace common\models\projectcontract;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\projectcontract\ProjectContract;

/**
 * ProjectContractSearch represents the model behind the search form about `common\models\projectcontract\ProjectContract`.
 */
class ProjectContractSearch extends ProjectContract
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'category', 'starttime', 'endtime', 'schedule_budget', 'schedule_starttime', 'schedule_endtime', 'mainpart_age'], 'integer'],
            [['number', 'name', 'cname', 'management', 'bearunit', 'bear_property', 'part_unit', 'bear_address', 'bear_postcode', 'unit_leader', 'unit_profession', 'unit_telephone', 'unit_mobile', 'unit_email', 'unit_fax', 'proj_leader', 'proj_profession', 'proj_telephone', 'proj_mobile', 'proj_email', 'proj_fax', 'proj_target', 'main_task', 'schedule_target', 'paid_content', 'paid_note', 'calculation_basis', 'mainpart_name', 'mainpart_profession', 'mainpart_unit', 'mainpart_mainwork', 'common_clause', 'account_name', 'bank_deposit', 'bank_account', 'fina_leader', 'depart_leader'], 'safe'],
            [['paid_money'], 'number'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = ProjectContract::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'category' => $this->category,
            'starttime' => $this->starttime,
            'endtime' => $this->endtime,
            'schedule_budget' => $this->schedule_budget,
            'schedule_starttime' => $this->schedule_starttime,
            'schedule_endtime' => $this->schedule_endtime,
            'paid_money' => $this->paid_money,
            'mainpart_age' => $this->mainpart_age,
        ]);

        $query->andFilterWhere(['like', 'number', $this->number])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'cname', $this->cname])
            ->andFilterWhere(['like', 'management', $this->management])
            ->andFilterWhere(['like', 'bearunit', $this->bearunit])
            ->andFilterWhere(['like', 'bear_property', $this->bear_property])
            ->andFilterWhere(['like', 'part_unit', $this->part_unit])
            ->andFilterWhere(['like', 'bear_address', $this->bear_address])
            ->andFilterWhere(['like', 'bear_postcode', $this->bear_postcode])
            ->andFilterWhere(['like', 'unit_leader', $this->unit_leader])
            ->andFilterWhere(['like', 'unit_profession', $this->unit_profession])
            ->andFilterWhere(['like', 'unit_telephone', $this->unit_telephone])
            ->andFilterWhere(['like', 'unit_mobile', $this->unit_mobile])
            ->andFilterWhere(['like', 'unit_email', $this->unit_email])
            ->andFilterWhere(['like', 'unit_fax', $this->unit_fax])
            ->andFilterWhere(['like', 'proj_leader', $this->proj_leader])
            ->andFilterWhere(['like', 'proj_profession', $this->proj_profession])
            ->andFilterWhere(['like', 'proj_telephone', $this->proj_telephone])
            ->andFilterWhere(['like', 'proj_mobile', $this->proj_mobile])
            ->andFilterWhere(['like', 'proj_email', $this->proj_email])
            ->andFilterWhere(['like', 'proj_fax', $this->proj_fax])
            ->andFilterWhere(['like', 'proj_target', $this->proj_target])
            ->andFilterWhere(['like', 'main_task', $this->main_task])
            ->andFilterWhere(['like', 'schedule_target', $this->schedule_target])
            ->andFilterWhere(['like', 'paid_content', $this->paid_content])
            ->andFilterWhere(['like', 'paid_note', $this->paid_note])
            ->andFilterWhere(['like', 'calculation_basis', $this->calculation_basis])
            ->andFilterWhere(['like', 'mainpart_name', $this->mainpart_name])
            ->andFilterWhere(['like', 'mainpart_profession', $this->mainpart_profession])
            ->andFilterWhere(['like', 'mainpart_unit', $this->mainpart_unit])
            ->andFilterWhere(['like', 'mainpart_mainwork', $this->mainpart_mainwork])
            ->andFilterWhere(['like', 'common_clause', $this->common_clause])
            ->andFilterWhere(['like', 'account_name', $this->account_name])
            ->andFilterWhere(['like', 'bank_deposit', $this->bank_deposit])
            ->andFilterWhere(['like', 'bank_account', $this->bank_account])
            ->andFilterWhere(['like', 'fina_leader', $this->fina_leader])
            ->andFilterWhere(['like', 'depart_leader', $this->depart_leader]);

        return $dataProvider;
    }
}
